
import Vue from 'vue'
import VueRouter from 'vue-router'



Vue.use(VueRouter)

const leftmenu =() => import('views/leftmenu/leftmenu')
const article =() => import('views/article/article')
const comment =() => import('views/comment/comment')
const fans =() => import('views/fans/fans')
const image =() => import('views/image/image')
const publish =() => import('views/publish/publish')
const settings =() => import('views/settings/settings')
const login =()=>import('views/login/login')
const routes = [
  {
    path:'/',
    redirect: '/home'
  },
  {
    path:'/login',
    component:login
  },
  {
   path:'/home',
   component:leftmenu,
   children:[
    {
      path:'/settings',
      component:settings
    },{
      path:'/article',
      component:article
    },{
      path:'/comment',
      component:comment
    },{
      path:'/fans',
      component:fans
    },{
      path:'/image',
      component:image
    },{
      path:'/publish',
      component:publish
    }
   ]
 }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to, from, next) => { 

 if(to.path !== '/login'){
  const token = window.sessionStorage.getItem('token')
  if(token){ 
    next()
  }else{
     next('/login')
  }
 }else{
   next()
 } 
})



export default router
